#include <types.h>
#include <pm.h>
#include <string.h>
#include <printk.h>
#include <int.h>

static struct idt_desc idtTable[NR_IDT];
struct desc_ptr idtPtr;
uint8_t idtCount;

void idt_install(uint8_t num, uint32_t base, uint16_t selctor, uint8_t attr)
{
    idtTable[num].base_low = (base & 0xffff);
    idtTable[num].base_high = (base >> 16) & 0xffff;

    idtTable[num].selector = selctor; 
    idtTable[num].always0 = 0; 
    idtTable[num].gate_type = 0x0f & attr;
    idtTable[num].flags = 0x0f & (attr >> 4);
}

void arch_idt_init()
{
    idtPtr.limit = (sizeof (struct idt_desc) * NR_IDT) - 1;
    idtPtr.base = (uint32_t)&idtTable;
    idt_table_init();
}